package com.example.spring.controller;

import com.example.spring.entity.Msg;
import com.example.spring.entity.UserBean;
import com.example.spring.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@ResponseBody
@CrossOrigin("http://localhost:5173")
public class UserController {
    @Resource
    UserService userService;

    /**
     * 用户注册接口
     *
     * @param user 用户信息
     * @return 注册结果，如果注册成功，会携带注册成功的用户信息(屏蔽了密码)
     */
    @PostMapping(value = "/signup", produces = "application/json")
    public Msg<UserBean> signup(@RequestBody UserBean user) {
        return userService.signup(user);
    }

    /**
     * 用户登录接口
     *
     * @param user 用户信息
     * @return 登录结果，如果登录成功，会携带登录成功的用户信息(屏蔽了密码)
     */
    @PostMapping(value = "/login", produces = "application/json")
    public Msg<UserBean> login(@RequestBody UserBean user) {
        return userService.login(user);
    }
}
